<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-04 16:53:56
 * @LastEditTime: 2023-09-22 14:47:16
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 加料单
 */

namespace App\Http\Services\Finance;


use App\Http\Services\Service;
use App\Repositories\FinanceTransferRepository;
use App\Repositories\FinanceVoucherRepository;
use Illuminate\Support\Facades\DB;

/**
 * @property FinanceTransferRepository $repository
 * @property FinanceVoucherRepository $voucher
 */
class TransferService extends Service
    {

    public function boot(FinanceTransferRepository $repository, FinanceVoucherRepository $voucher)
        {
        $this->repository = $repository;
        $this->voucher    = $voucher;
        }

    public function list()
        {
        $data = $this->repository->condition()->getGrid();
        return $data;
        }
    protected function save()
        {
        return $this->repository->autosave(request()->toArray());
        }

    protected function audit()
        {
        return $this->repository->whereIn("id", $this->getRequestIds())->get()->filter(function ($v)
            {
            auditSave($v);
            $v->finance();
            });
        }
    protected function noaudit()
        {
        return $this->repository->whereIn("id", $this->getRequestIds())->get()->filter(function ($v)
            {
            $v->nofinance();
            auditSave($v, false);
            });
        }
    protected function delete()
        {
        return $this->repository->whereIn("id", $this->getRequestIds())->get()->filter(function ($v)
            {
            if ($v->status_id != 0) {
                fail("转账已{$v->status->name},删除失败！");
                }
            $v->delete();
            });
        }
    }